package main;


import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

import Database.LoginHandler;

import connectionHandler.*;
import encoding.*;
import tokenizer.*;
import stompProtocol.*;

public class StompServer
{
	public static boolean isForumServerConnected = false;
	
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		Encoder encoder = new SimpleEncoder("UTF-8");
		ServerSocket socket = new ServerSocket(61635);
		LoginHandler logHand = new LoginHandler();
		while (true)
		{
			Socket s = socket.accept();
			Tokenizer tokenizer = new StompTokenizer(new InputStreamReader(s.getInputStream(),encoder.getCharset()),'\0');
			Sender sender = new Sender(s,encoder);
			StompProtocol protocol = new StompServerProtocol(sender, logHand);
			Runnable connectionHandler = new ConnectionHandler(s, tokenizer, protocol);
			new Thread(connectionHandler).start(); // NOTE HERE: Each connection handler runs in a different thread
		}
	}
}

